package com.imay.live.helper;

import com.imay.tbas_api.IMYTBASObject;

/**
 * Created by jeaman on 2017/4/1.
 * 事件消息通知
 */

public class EventHelper {
    public final static String EVENT_SOCK_NOTIFY = "SOCK_NOTIFY"; //监听socket
    public final static String EVENT_LOGIN_SUCCESS = generateEventName();   //登录成功
    public final static String EVENT_FOLLOW_USER = generateEventName(); //关注用户
    public final static String EVENT_UN_FOLLOW_USER = generateEventName(); //取消关注用户
    public final static String EVENT_UPDATE_USER_INFO = generateEventName(); //更新用户信息
    public final static String EVENT_FOLLOW_UICHANGE = generateEventName(); //关注用户变化按钮马上改变
    public final static String EVENT_GIFT_LOADED = generateEventName(); //礼物列表变化
    public final static String EVENT_DYNAMICS_UPDATE = generateEventName(); // 动态数据变化
    public final static String EVENT_MESSAGE_NOTIFY = generateEventName(); // 收到私信,发送消息
    public final static String EVENT_MESSAGE_SEND = generateEventName(); // 发送消息,刷新私信列表
    public final static String EVENT_UNREAD = generateEventName(); // 未读红点消息
    public final static String EVENT_PROFILE_MONEY = generateEventName(); // 个人页金钱等监听
    public final static String EVENT_PROFILE_LEVEL = generateEventName(); // 个人页等级监听
    public final static String EVENT_DYNAMICS_NOTIFY = generateEventName(); // 动态直播通知
    public final static String EVENT_NAMESTATUS = generateEventName(); // 实名认证状态变化
    public final static String EVENT_USERSIGN = generateEventName(); // 签约状态变化
    public final static String EVENT_NO_LOGIN = generateEventName(); // 未登录
    public final static String EVENT_APPUPDATE = generateEventName(); // APK 升级
    public final static String EVENT_DATASET = generateEventName(); // 登录完成,信息更新通知
    public final static String EVENT_UPDATE_PROFILE_SHORT_LVEE = generateEventName(); // 挑战完成自动刷新个人页列表
    public final static String EVENT_FAMILY_USER_CHANGE = generateEventName(); // 家族人员管理操作
    public final static String EVENT_FAMILY_NOTIFY = generateEventName(); // 家族通知操作
    public final static String EVENT_RECHARGE_SUCCESS_NOTIFY = generateEventName(); // 充值成功

    //Event事件ID，自动生成id值
    private static int EVENT_ID = 0;

    protected static String generateEventName() {
        return "EVENT_" + (++EVENT_ID);
    }

    private static void postEvent(String command) {
        postEvent(command, null);
    }

    private static void postEvent(String command, String data) {
        IMYTBASObject event = new IMYTBASObject();
        event.stringCommand = command;
        event.stringData = data;
        event.postEventWithTBASObject();
    }

    //登录成功
    public static void postLoginSuccess() {
        postEvent(EVENT_LOGIN_SUCCESS);
    }

    //关注用户
    public static void postFollowUser(long uid) {
        postEvent(EVENT_FOLLOW_USER, String.valueOf(uid));
    }

    //取消关注用户
    public static void postUnFollowUser(long uid) {
        postEvent(EVENT_UN_FOLLOW_USER, String.valueOf(uid));
    }

    //更新用户信息
    public static void postUpdateUserInfo() {
        postEvent(EVENT_UPDATE_USER_INFO);
    }

    //点击了 升级弹窗
    public static void postUpdateOnclice() {
        postEvent(EVENT_APPUPDATE);
    }

    //关注用户变化
    public static void postFollowChange(long uid, boolean follow) {
        if (follow) {
            postEvent(EVENT_FOLLOW_UICHANGE, String.valueOf(uid));
        } else {
            postEvent(EVENT_FOLLOW_UICHANGE, uid + "#");//说明是取消用户关注
        }
    }

    //签约成功
    public static void postSignChange() {
        postEvent(EVENT_USERSIGN, "{\"content\":{\"meiliGain\":3832},\"msg_id\":329,\"seq\":0}");
    }

    //本地实名认证状态
    public static void postAuthChange(int realNameStatus) {
        postEvent(EVENT_NAMESTATUS, "{\"content\":{\"realNameStatus\":" + realNameStatus + "},\"msg_id\":238,\"seq\":0}");
    }

    //礼物列表下载成功
    public static void postGiftLoaded() {
        postEvent(EVENT_GIFT_LOADED);
    }

    // 更新动态数据监听
    public static void postDynamicsUpdate(String feedString) {
        postEvent(EVENT_DYNAMICS_UPDATE, feedString);
    }

    // 收到消息,发送刷新界面通知
    public static void postMessageNotify(String content) {
        postEvent(EVENT_MESSAGE_NOTIFY, content);
    }

    // 发送消息,发送刷新界面通知
    public static void postMessageSend(String content) {
        postEvent(EVENT_MESSAGE_SEND, content);
    }

    // 红点显示/隐藏消息
    public static void postUnread(String content) {
        postEvent(EVENT_UNREAD, content);
    }


    // 个人页金钱相关信息
    public static void postProfileMoneyInfo(String content) {
        postEvent(EVENT_PROFILE_MONEY, content);
    }

    // 个人页等级
    public static void postProfileLevelInfo(String content) {
        postEvent(EVENT_PROFILE_LEVEL, content);
    }

    // 红点显示/隐藏消息
    public static void postDynamicsNotify(String content) {
        postEvent(EVENT_DYNAMICS_NOTIFY, content);
    }


    // Main的接口未登录时，进行互斥显示
    public static void postUserNoLogin() {
        postEvent(EVENT_NO_LOGIN);
    }

    /**
     * 登录更新信息
     *
     * @param status
     */
    public static void postDataSet(String status) {
        postEvent(EVENT_DATASET, status);
    }

    //挑战完成自动刷新个人页列表
    public static void postUpdateShortLiveProfile() {
        postEvent(EVENT_UPDATE_PROFILE_SHORT_LVEE);
    }

    // 家族人员操作
    public static void postFamilyUserChange(String action) {
        postEvent(EVENT_FAMILY_USER_CHANGE, action);
    }

    // 家族操作
    public static void postFamily(String action) {
        postEvent(EVENT_FAMILY_NOTIFY, action);
    }

    // 充值成功
    public static void postRechargeSuccess() {
        postEvent(EVENT_RECHARGE_SUCCESS_NOTIFY);
    }
}
